from bs4 import BeautifulSoup
def parse_category_cards(self,html):
    soup = BeautifulSoup(html, 'html.parser')
    cards = soup.find_all('li', class_='a-carousel-card')
    categories = []
    for card in cards:
        category = {}
        link = card.find('a', class_='a-color-base')
        if link:
            category['url'] ='https://www.amazon.com' + link.get('href', '')
        img = card.find('img')
        if img:
            category['image_url'] = img.get('src', '')
            # 有些图片可能存储在 data-a-dynamic-image 属性中
            dynamic_images = img.get('data-a-dynamic-image', '')
            if dynamic_images:
                category['dynamic_images'] = dynamic_images
        
        # 获取分类名称
        category_name = card.find('span', class_='a-size-base-plus')
        if category_name:
            category['name'] = category_name.text.strip()
            
        categories.append(category)
    
    return categories

# 使用示例
html = '''你的HTML内容'''
results = parse_category_cards(html)
for result in results:
    print(f"Category: {result.get('name')}")
    print(f"URL: {result.get('url')}")
    print(f"Image URL: {result.get('image_url')}")
    print("---")